package com.dx.chat.kafka.core;

import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * spel获取kafka主题、bean信息
 *
 * @author wcx
 * @date 2023/6/28
 */
@Component(value = "kafkaTopicInfo")
public class KafkaTopicInfo {

    @Resource
    private KafkaConfig kafkaConfig;


    /**
     * 获取kafka topic
     *
     * @param index yml配置的下标
     * @return {@link String}
     */
    public String getTopic(Integer index) {
        if (Objects.isNull(index)) {
            return null;
        }
        return kafkaConfig.getDxTopics().get(index).getName();
    }

    /**
     * 获取kafka beanName
     *
     * @param topicIndex    topic配置的下标
     * @param consumerIndex consumer配置的下标
     * @return {@link String}
     */
    public String getConsumerBeanName(Integer topicIndex, Integer consumerIndex) {
        if (Objects.isNull(topicIndex) || Objects.isNull(consumerIndex)) {
            return null;
        }
        return kafkaConfig.getDxTopics().get(topicIndex).getConsumers().get(consumerIndex).getConsumerBeanName();
    }

}
